package com.movie.demo.controller;

import com.movie.demo.Utlis.result.CommonResult;
import com.movie.demo.pojo.Arrange;
import com.movie.demo.pojo.Cinema;
import com.movie.demo.pojo.vo.Arrangeinfo;
import com.movie.demo.service.ArrangeService;
import com.movie.demo.service.CinemaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@CrossOrigin
public class ArrangeController {

    @Autowired
    private ArrangeService arrangeService;
    @PostMapping("/arrange")
    public CommonResult<List> select(){
        List<Arrangeinfo> arrangeinfos = arrangeService.selectArrange();
        if(arrangeinfos!=null){
            return CommonResult.success(arrangeinfos);
        }
        return CommonResult.failed();
    }
    @PostMapping("/addArrange")
    public CommonResult<Boolean> addArrange(@RequestBody Arrange arrange){
        boolean result=arrangeService.addArrange(arrange);
        if (result){
            return CommonResult.success(result);
        }
        return  CommonResult.failed();
    }
    @PostMapping("/updateArrangeState")
    public CommonResult<Boolean> updateState(@RequestBody Arrange arrange){
        boolean result=arrangeService.updateState(arrange.getId());
        if (result){
            return CommonResult.success(result);
        }
        return  CommonResult.failed();
    }
    @PostMapping("/DeleteArrange")
    public CommonResult<Boolean> DeleteArrange(@RequestBody Arrange arrange){
        boolean result=arrangeService.DeleteArrange(arrange.getId());
        if (result){
            return CommonResult.success(result);
        }
        return  CommonResult.failed();
    }
    @PostMapping("/UpdateArrange")
    public CommonResult<Boolean> UpdateArrange(@RequestBody Arrange arrange){
        boolean result=arrangeService.UpdateArrange(arrange);
        if (result){
            return CommonResult.success(result);
        }
        return  CommonResult.failed();
    }
    @PostMapping("/ArrangeTime")
    public CommonResult<List> ArrangeTime(@RequestBody Arrange arrange){
        List<Arrange> arrangeList=arrangeService.ArrangeTime(arrange.getMid(),arrange.getCid(),arrange.getRid());
        if (arrangeList!=null){
            return CommonResult.success(arrangeList);
        }
        return  CommonResult.failed();
    }
}